import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.VkontakteApi;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;

public class Share {

	private final String clientId = "2804045";
	private final String apiSecret = "Z9saMrZOrG6Reqjr3MQt";
	private final String redirect_uri = "http://api.vk.com/blank.html/callback";
	private static String WallPostMessage = "https://api.vkontakte.ru/method/wall.post?message=";
	private static final Token EMPTY_TOKEN = null;

	public Share(final String Code, String message) {

		try {

			WallPostMessage += URLEncoder.encode(message, "UTF-8");
		} catch (UnsupportedEncodingException e) {

			e.printStackTrace();
		}

		OAuthService service = new ServiceBuilder()
				.provider(VkontakteApi.class).apiKey(clientId)
				.apiSecret(apiSecret).scope("wall").callback(redirect_uri)
				.build();

		// String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);

		Verifier verifier = new Verifier(Code);

		Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);

		OAuthRequest request = new OAuthRequest(Verb.GET, WallPostMessage);
		service.signRequest(accessToken, request);
		@SuppressWarnings("unused")
		Response response = request.send();

		// System.out.println(response.getCode());
		// System.out.println(response.getBody());
	}
}